PID Servo Tuning / Troubleshooting

There are generally three settings you must adjust to make a PID based controller work correctly:

Ziegler / Nichols Starting Point: There are several ways to tune a PID controller, these steps present the Ziegler / Nichols closed loop method as a starting point. Further "trial and error" tuning should certainly be used: (Commands for the BOB PID system will be shown in parenthesis after each step... your systems commands may vary. For e.g. Arduino or other hard coded systems, adjust the parameters in the sketch before programming each time.)

  1. No I or D, Little P Start with the I and D terms set to 0 and P set to a very small value. (0i0d1p)
     
  2. Power up, set desired position to 1 (1{enter}) and make sure you have direction set correctly (216w or 286w) and enable the driver (e), If the servo just spins and spins, it's doing a zig when it should zag... the direction is probably wrong; disable the driver ({space}) and try the other direction before enabling again.
     
  3. While(!Oscillating) P++; Slowly increase the P constant while moving from one point to another and back until the unit starts to oscillate with a consistent motion, back and forth the same amount. (1p100{enter}1{enter}2p100{enter}1{enter}...) To save time, you can use an exponential and then binary search. Start with 1, then 10, then 100, then 1000, etc… until you get oscillation. Then divide that number in 2; if it still oscillates, divide by two again, otherwise, add half the current value back. E.g. from 100, try 50, if it oscillates, try 25, if not, try 75 = 50/2+50. And so on.
     
  4. This setting for P is called the Ku or "ultimate gain". Record it, and count the number of oscillations per second, which is called the frequency or Tu. Be sure to then change Tu into units matching the sample time used in the controller. E.g. the BOB PID uses ¼ second updates, so divide your measurement by 4.
     
  5. Now you can use these values to calculate good starting points for the P, I, and D terms:
     

Now try moving back and forth and see how the system reacts. Make both short and long jumps, small and large movements. e.g. (10{enter}1{enter}200{enter}1{enter}...) If it starts oscillating out of control, disable the motor and continue with troubleshooting below. ({space}) Be sure to give it time to settle at each point, and ensure it really does make it to exactly the desired point (mark the shaft if you can).

Once you have the tuning done, save the values to non-volatile memory {321w}

PID Troubleshooting

Oscillation: If you have a very heavy shaft, meaning a lot of mass turning on the shaft especially away from the center of rotation; this has nothing to do with the weight of the load being moved unless that load is spinning with the shaft, then increase D until you start to hear shuddering or vibration as it approaches a new setpoint. If you have a lot of overshoot when approaching a new setpoint, decrease I. Otherwise, decrease P.

Slow approach to setpoint: If you have a lot of friction in the system, increase I. If the system "grinds" or "shudders" or vibrates as it approaches the setpoint, decrease D. Otherwise increase P.

Overshoot (without oscillation): Decrease P.

See also: